package com.qyc.utils;

import com.qyc.constant.SystemConstants;
import com.qyc.enums.CodeMsgEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @className: ResponseResult
 * @Description: 统一响应类
 * @author: qinyc
 * @date: 2023/6/20 16:31
 * @version: v1.0
 */
@Data
@ApiModel("统一响应类")
public class ResponseResult<T> {
    //响应状态码
    @ApiModelProperty("响应状态码")
    private int code;

    //响应信息
    @ApiModelProperty("响应信息")
    private String message;

    //响应数据
    @ApiModelProperty("响应数据")
    private T data;

    /**
     * @Author qinyc
     * @Description  构造器（只含状态码和响应信息----枚举）
     * @version: v1.0
     * @Date 17:48 2023/6/20
     **/
    public ResponseResult(CodeMsgEnum codeMsgEnum) {
        this.code = codeMsgEnum.getCode();
        this.message = codeMsgEnum.getMsg();
    }

    /**
     * @Author qinyc
     * @Description  构造器（只含状态码和响应信息----自定义）
     * @version: v1.0
     * @Date 17:48 2023/6/20
     **/
    public ResponseResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @Author qinyc
     * @Description  构造器（只含有枚举类【响应状态码和响应信息】和数据）
     * @version: v1.0
     * @Date 17:49 2023/6/20
     **/
    public ResponseResult(CodeMsgEnum codeMsgEnum,T data) {
        this.code = codeMsgEnum.getCode();
        this.message = codeMsgEnum.getMsg();
        this.data = data;
    }

    /**
     * @Author qinyc
     * @Description  构造器（全参）
     * @version: v1.0
     * @Date 17:48 2023/6/20
     **/
    public ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * @Author qinyc
     * @Description  成功响应无参
     * @version: v1.0
     * @Date 16:33 2023/6/20
     **/
    public static ResponseResult success(){
        return new ResponseResult(CodeMsgEnum.SUCCESS);
    }

    /**
     * @Author qinyc
     * @Description  成功响应（只传递data数据）
     * @version: v1.0
     * @Date 17:45 2023/6/20
     **/
    public static <T> ResponseResult<T> success(T data){
        return new ResponseResult<T>(CodeMsgEnum.SUCCESS,data);
    }

    /**
     * @Author qinyc
     * @Description  成功响应（自定义响应信息和响应数据）
     * @version: v1.0
     * @Date 17:56 2023/6/20
     **/
    public static <T> ResponseResult<T> success(String msg,T data){
        return new ResponseResult<T>(SystemConstants.SUCCESS_CODE,msg,data);
    }



    /**
     * @Author qinyc
     * @Description  错误响应（无参）
     * @version: v1.0
     * @Date 18:00 2023/6/20
     **/
    public static ResponseResult error(){
        return new ResponseResult(CodeMsgEnum.ERROR);
    }

    /**
     * @Author qinyc
     * @Description  错误响应（只传递data数据）
     * @version: v1.0
     * @Date 18:02 2023/6/20
     **/
    public static <T> ResponseResult<T> error(int code,String msg){
        return new ResponseResult<T>(code,msg);
    }
}
